package android.app.betmein.activity;

import android.app.ActionBar;
import android.app.betmein.R;
import android.content.Intent;
import android.framework.paging.SingleViewActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

public abstract class NavigationBaseActivity extends SingleViewActivity{
	
	protected Class<?> parentActivity = EntitiesActivity.class;
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		ActionBar actionBar = getActionBar();
	    actionBar.setDisplayHomeAsUpEnabled(true);
	}
	
	@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		  switch (item.getItemId()) {
	        case android.R.id.home:
	            // This is called when the Home (Up) button is pressed
	            // in the Action Bar.
	        	if(parentActivity != null){
		            Intent parentActivityIntent = new Intent(this, parentActivity);
		            parentActivityIntent.addFlags(
		                    Intent.FLAG_ACTIVITY_CLEAR_TOP |
		                    Intent.FLAG_ACTIVITY_NEW_TASK);
		            startActivity(parentActivityIntent);
	        	}
	            finish();
	            return true;
	    }
	    return super.onOptionsItemSelected(item);
	}
	
}
